/* 
 * File:   DirectoryEntry.cpp
 * Author: Usama Shaikh
 * 
 * Created on February 20, 2011, 12:01 PM
 */

#include "DirectoryEntry.h"
#include <stdio.h>
#include <unistd.h>
#include <iostream>

/**
 * Default Constructor that initializes a Directory Entry object. This method
     * does not set the filename or fcb, just initializes an entry
 */
DirectoryEntry::DirectoryEntry() {

    m_fcbNumber = 0;
    //m_fileName = ;

}

/**
 * A constructor to create a new Directory Entry with the passed in filename
 * and file control block.
 * @param inFileName Name of the file
 * @param fcbNumber
 */
DirectoryEntry::DirectoryEntry(char* name, int number) {

    m_fcbNumber = number;
    strcpy(m_fileName,name);
    m_fileName[FILENAME_LENGTH-1]= NULL;
    //m_fileName = name;

}

/**
 * Deconstructor for the Directory Entry object.
 */
DirectoryEntry::~DirectoryEntry() {
   // delete [] m_fileName;
}

/**
 * Set File Name method takes in a new file name to change to current file name
 * to the new one.
 * @param inFileName New file name for this object
 */
void DirectoryEntry::SetFileName(char* name) {
//    delete [] m_fileName;
//    m_fileName = NULL;
//    m_fileName = name;
    strcpy(m_fileName,name);
    m_fileName[FILENAME_LENGTH-1]= NULL;
}

/**
 * Set File Control Block takes in a new fcb to change the current fcb to the
 * new one.
 * @param inFcb New File Control Block for this object
 */
void DirectoryEntry::SetFileControlBlock(int number) {
    m_fcbNumber = number;
}

/**
 * Get File name returns the file name of the directory entry.
 * @return A char pointer to the file name
 */
char* DirectoryEntry::GetFileName() {
    return m_fileName;
}

/**
 * Get File Control Block returns the fcb of the directory entry.
 * @return A FileControlBlock pointer to the fcb
 */
int DirectoryEntry::GetFileControlBlock() {
    return m_fcbNumber;
}


void DirectoryEntry::Test() {
        int cmd = 0;
        DirectoryEntry test = DirectoryEntry("Atmosphere", 5);

        for (;;) {
            //unsigned char m_buffer[Disk::DEFAULT_BLOCK_SIZE] = "abcdesf";
            printf("\nmain: Enter command:\n");
            printf("   0) Exit program\n");
            printf("   1) getFileControlBlock\n");
            printf("   2) getFileName \n");
            printf("   3) setFileControlBlock\n");
            printf("   4) setFileName\n");

//        unsigned char *block = new unsigned char[Disk::DEFAULT_BLOCK_SIZE];

            printf("Enter command: ");
            scanf("%d", &cmd);

            switch (cmd) {
                case 0:
                    exit(EXIT_SUCCESS);
                    break;

                case 1: // getFileControlBlock
                    printf("The FCB Number is %d\n",test.GetFileControlBlock());
                    break;
                case 2: // getFileName
                    printf("The Filename is %s\n",test.GetFileName());
                    break;
                case 3: // SetFileControlBlock
                    test.SetFileControlBlock(27);
                    printf("The FCB Number has been set!\n");
                    break;
                case 4: // setFileName
                    test.SetFileName("Slug Life");
                    printf("The FileName has been set!\n");
                    break;
                default:
                    printf("main: Bad command!\n");
                    break;
            } // end switch
        } // end for
    } // end Test()
